﻿/* ######################################## *\
 * ### Copyright (C) 2009 AJ Ravindiran ### *
\* ######################################## */
using System;
using System.Text;

namespace AJRavindiran.Jolt.Utilities
{
    /// <summary>
    /// Represents string related utilities
    /// </summary>
    public static class StringUtilities
    {
        #region Fields
        private static char[] validCharacters =
        {
            '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
            'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 
            't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', 
            '3', '4', '5', '6', '7', '8', '9'
        };
        #endregion Fields

        #region Properties
        /// <summary>
        /// Gets valid characters.
        /// </summary>
        public static char[] ValidCharacters
        {
            get { return validCharacters; }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Java's equalsIgnoreCase method.
        /// </summary>
        public static bool EqualsIgnoreCase(this string value, string compare)
        {
            return (compare.ToLower() == value.ToLower());
        }

        /// <summary>
        /// Formats a given string to suitable protocol format.
        /// </summary>
        public static string FormatForProtocol(string s)
        {
            s = s.Replace(" ", "_");
            s = s.ToLower();
            return s;
        }

        /// <summary>
        /// Formats a given string for display (eg. ingame).
        /// </summary>
        public static string FormatForDisplay(string s)
        {
            return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s).Replace('_', ' ');
        }
        #endregion 
    }
}
